package com.wanglei.rdd.action

import org.apache.spark.{SparkConf, SparkContext}

object Spark07_rddclosure {

  class User extends Serializable {
    val age: Int = 20
  }

  def main(args: Array[String]): Unit = {

    //
    val conf = new SparkConf().setMaster("local[2]").setAppName("map")
    val sc = new SparkContext(conf)


    val rdd = sc.makeRDD(List(
      1, 2, 3, 4
    ))

    val user = new User

    // 直接foreach其实是在executor中打印的
    // 闭包检测
    //
    rdd.foreach(
      num => {
        println("age = " + user.age + ",num = " + num)
      }
    )

    sc.stop()

  }

}

